package com.hnqcgczy.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MyConncetion implements IConnection{
    // 连接地址  连接账号  连接密码
    public final String URL="jdbc:mysql://localhost:3306/dujiaoshou?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
    public final String USERNAME="root";
    public final String PASSWORD="123456";

    /***
     * 注册驱动
     */
    static{
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    public Connection getConnectionByMysql() throws SQLException {
        Connection conn= DriverManager.getConnection(URL,USERNAME,PASSWORD);
        return conn;
    }

    @Override
    public Connection getConnectionByOracle() throws SQLException {
        return null;
    }

    public static void main(String[] args) {
        MyConncetion myconn=new MyConncetion();
        try {
            Connection connbyMysql=myconn.getConnectionByMysql();
            System.out.println(connbyMysql.isClosed());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
